/**
 * 处理角色自动搜索框数据
 * @param dataList
 * @param searchValue
 * @param dataName
 * @returns
 */
const autoOptionRole = (dataList: Record<string, any>[], searchValue: string, dataName: string) => {
  let option: Record<string, any>[] = [];
  const tileTreeData = (data: Record<string, any>[]) => {
    data?.forEach((item) => {
      if (item?.children && item?.children?.length > 0) {
        tileTreeData(item?.children);
      }
      if (!searchValue) {
        option.push({
          value: item?.[dataName],
          key: item?.id,
          itemrowobj: { ...item },
        });
      } else if (item?.[dataName]?.includes(searchValue)) {
        option.push({
          value: item?.[dataName],
          key: item?.id,
          itemrowobj: { ...item },
        });
      }
    });
  };
  tileTreeData(dataList);
  return option;
};

export { autoOptionRole };
